﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Wpf_Tool_ZC.util;

namespace Wpf_Tool_ZC
{
    /// <summary>
    /// WndHuanJingBianLiang.xaml 的交互逻辑
    /// </summary>
    public partial class WndHuanJingBianLiang : Window
    {
        public WndHuanJingBianLiang()
        {
            InitializeComponent();
        }

        private void Click_BiJiao(object sender, RoutedEventArgs e)
        {
            string str1 = @"C:\path_1053.txt";
            string str2 = @"C:\lib.txt";

            List<string> list1 = new List<string>();
            List<string> list2 = new List<string>();

            List<string> list = UtilFile.ReadTxt(str1);
            tbMsg.AppendText("环境变量 文件("+ str1 + "): 共"+ list.Count + "行. \r\n");
            for (int i = (list.Count - 1); i >= 0; i--)
            {
                //tbMsg.AppendText(list1[i] + "\r\n");
                string[] strs1 = list[i].Split(';');
                if (strs1.Length > 0)
                {
                    for (int j = 0; j < strs1.Length; j++)
                        list1.Add(strs1[j].Trim());
                }
            }
            tbMsg.AppendText("解析后 共" + list1.Count + "行. \r\n");
            for (int i = 0; i < list1.Count; i++)
                tbMsg.AppendText("\t" + list1[i] + "\r\n");

            tbMsg.AppendText("\r\n");

            list = UtilFile.ReadTxt(str2);
            tbMsg.AppendText("环境变量 文件(" + str2 + "): 共" + list.Count + "行. \r\n");
            for (int i = (list.Count - 1); i >= 0; i--)
            {
                //tbMsg.AppendText(list1[i] + "\r\n");
                string[] strs1 = list[i].Split(';');
                if (strs1.Length > 0)
                {
                    for (int j = 0; j < strs1.Length; j++)
                        list2.Add(strs1[j].Trim());
                }
            }
            tbMsg.AppendText("解析后 共" + list2.Count + "行. \r\n");
            for (int i = 0; i < list2.Count; i++)
                tbMsg.AppendText("\t" + list2[i] + "\r\n");


            tbMsg.ScrollToEnd();

            List<string> listDiff = new List<string>();
            UtilList.BiJiao_str(list1, list2, null, listDiff);

            tbMsg.AppendText("\r\n");
            tbMsg.AppendText("比较后，不同的项：（个数："+ listDiff .Count+ "）\r\n");
            for (int i = 0; i < listDiff.Count; i++)
                tbMsg.AppendText("\"" + listDiff[i] + "\";\r\n");
                //tbMsg.AppendText(listDiff[i] + ";");

            //tbMsg.AppendText("\r\n");
            //tbMsg.AppendText("新增path：\r\n");
            //string str = "";
            //for (int i = 0; i < listDiff.Count; i++)
            //    str += "\""+ listDiff[i] + "\";";
            //tbMsg.AppendText("set path=%path%;"+str);

        }

        private void Click_HeBing(object sender, RoutedEventArgs e)
        {
            string str = @"D:\Documents\Downloads\botan\path_z.txt";

            List<string> list1 = new List<string>();
            List<string> list2 = new List<string>();

            List<string> list = UtilFile.ReadTxt(str);

            tbMsg.AppendText("\r\n");
            tbMsg.AppendText("新增的 path 语句：\r\n");
            for (int i=0; i< list.Count; i++)
                tbMsg.AppendText(list[i]);

        }

        private void Click_ClearMsg(object sender, RoutedEventArgs e)
        {
            tbMsg.Clear();
        }

        private void Click_PrintPerLine(object sender, RoutedEventArgs e)
        {
            string str1 = @"C:\include_20191017_1049.txt";

            List<string> list1 = new List<string>();

            List<string> list = UtilFile.ReadTxt(str1);
            tbMsg.AppendText("环境变量 文件(" + str1 + "): 共" + list.Count + "行. \r\n");
            for (int i = (list.Count - 1); i >= 0; i--)
            {
                //tbMsg.AppendText(list1[i] + "\r\n");
                string[] strs1 = list[i].Split(';');
                if (strs1.Length > 0)
                {
                    for (int j = 0; j < strs1.Length; j++)
                        list1.Add(strs1[j]);
                }
            }
            tbMsg.AppendText("解析后 共" + list1.Count + "行. \r\n");
            for (int i = 0; i < list1.Count; i++)
                tbMsg.AppendText("\t" + list1[i] + "\r\n");


            tbMsg.AppendText("\r\n");
            tbMsg.AppendText("新增的 path 语句：\r\n");
            for (int i = 0; i < list1.Count; i++)
                tbMsg.AppendText("\""+list1[i]+"\";");
        }

        private void Click_1Line2Multi(object sender, RoutedEventArgs e)
        {
            string[] strs = tbMsg.Text.Split(';');

            tbMsg.AppendText("\r\n");
            tbMsg.AppendText("用';'分割后，共" + strs.Count() + "项. \r\n");
            for (int i = 0; i < strs.Count(); i++)
                tbMsg.AppendText(strs[i]+"\r\n");
        }

        private void Click_TbHeBing(object sender, RoutedEventArgs e)
        {
            string str = tbMsg.Text.Replace("\r\n", ";");
            tbMsg.AppendText("合并后的字符串为: \r\n" + str + "\r\n");

            //string[] strs = tbMsg.Text.Split('\n');
            //tbMsg.AppendText("用';'分割后，共" + strs.Count() + "项. \r\n");
        }
    }
}
